package com.mogist.hqc.module.order.presenter

import com.mogist.hqc.entitys.BaseResponse
import com.mogist.hqc.entitys.response.OrderListVo
import com.mogist.hqc.module.order.contract.OrderContract
import com.mogist.hqc.mvp.HttpDto
import com.mogist.hqc.mvp._PresenterImpl
import com.mogist.hqc.util.Constant
import talex.zsw.basecore.util.JsonTool
import talex.zsw.basecore.view.dialog.sweetalertdialog.SweetAlertDialog

/**
 * 作用：订单列表
 * 作者：赵小白 email:vvtale@gmail.com  
 * 修改人：
 * 修改时间：
 * 修改备注：
 */
class OrderPresenter(view: OrderContract.View) : _PresenterImpl<OrderContract.View, BaseResponse>(
        view), OrderContract.Presenter
{
    override fun requestSuccess(response: BaseResponse, http: HttpDto)
    {
        when (http.url)
        {
            Constant.ORDER_LIST   ->
            {
                mView.disLoading()
                if (response.success)
                {
                    mView.disDialog()
                    val vo = JsonTool.getObject(response.content, OrderListVo::class.java)
                    mView.bindData(vo)
                }
                else
                {
                    mView.showDialog(SweetAlertDialog.ERROR_TYPE, "获取订单列表失败", response.message)
                }
            }
            Constant.ORDER_CANCEL ->
            {
                if (response.success)
                {
                    mView.cancelSuccess()
                }
                else
                {
                    mView.showDialog(SweetAlertDialog.ERROR_TYPE, "取消订单失败", response.message)
                }
            }
            Constant.ORDER_COMMENT ->
            {
                if (response.success)
                {
                    mView.disDialog()
                    mView.commentSuccess()
                }
                else
                {
                    mView.showDialog(SweetAlertDialog.ERROR_TYPE, "发表评论失败", response.message)
                }
            }
        }
    }

    override fun requestError(msg: String?, httpDto: HttpDto?)
    {
        mView.disLoading()
        super.requestError(msg, httpDto)
    }
}